package network;

import java.net.DatagramPacket;
import java.net.InetAddress;
import java.nio.ByteBuffer;

public class Packet_ActorRequest extends Packet{

	public short [] m_uids;
	public byte m_length;
	
	public Packet_ActorRequest(int timestamp, short [] uids,byte length)
	{
		m_type=packettype.ACTOR_REQUEST;
		m_length=length;
		m_uids=uids;
		m_timestamp=timestamp;
		
	}
	
	public Packet_ActorRequest(DatagramPacket pack)
	{
		m_address=pack.getAddress();
		m_type=packettype.ACTOR_REQUEST;
		ByteBuffer buffer=ByteBuffer.wrap(pack.getData());
		Header(pack.getAddress(),buffer);	
		
		m_length=buffer.get();
		m_uids=new short [m_length];
		for (int i=0;i<m_length;i++)
		{
			m_uids[i]=buffer.getShort();
		}
	}
	
	public DatagramPacket Encode(InetAddress address, int port)
	{
		byte []buffer=new byte[1024];
		ByteBuffer BB=ByteBuffer.wrap(buffer);
		//encode type
		BB.put(getTypebyte(m_type));
		BB.putInt(m_timestamp);		
		
		BB.put(m_length);
		for (int i=0;i<m_length;i++)
		{
			BB.putShort(m_uids[i]);
		}
		return new DatagramPacket(buffer,buffer.length,address,port);
	}
}
